<%--
  Created by IntelliJ IDEA.
  User: oldliu
  Date: 2022-02-23
  Time: 14:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>cookie访问次数</title>
</head>
<body>
    <%
        //存放访问次数的那个cookie名叫visitnum
        Cookie v=null;
        Cookie[]cr=request.getCookies();
        if(cr!=null){
            for(Cookie ck :cr){
                if(ck.getName().equals("visitnum"))
                {
                    v=ck;
                    break;
                }
            }
        }
        if(v==null){
            v=new Cookie("visitnum","0");
        }
        int count=Integer.parseInt(v.getValue())+1;
        out.print("当前访问了"+count+"次");
        v.setValue(String.valueOf(count));
        v.setMaxAge(86400);
        response.addCookie(v);
    %>
</body>
</html>
